#include <header.h>

/**
 * 2. 利用mmap文件映射和read/write实现：
 * 将文件中的全部大写字母转换成对应的小写字母
*/
int main(int argc, char* argv[]){
	ARGS_CHECK(argc, 2);
	int fd = open(argv[1], O_RDWR);
	ERROR_CHECK(fd, -1, "open");


	struct stat sb;
	int ret = fstat(fd, &sb);
	ERROR_CHECK(ret, -1, "fstat");
	long size = sb.st_size;


	char* p = (char*)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	ERROR_CHECK(p, MAP_FAILED, "mmap");


	for(int i = 0; i < size; i++){
		p[i] = tolower(p[i]);
	}


	close(fd);
	return 0;
}